//
//web printer plugin, jyxd @copyright. 2021,
//v1.0,2021/06/27, no page breaking
//authour:Huangsong
//
export function jyxdPagePrint(printParam) {

    if (typeof printParam != "object") {
        alert("打印参数不正确!");
        return;
    }

    //border styles in new page
    const borderStyle = "1px solid #091020"////#091020";

    var printId = ""; // print_id: "myprint_div" 打印区最外范围id, div 或 el-dialog

    var tableId = ""; // table_id: "mytable" 表格的id
    var titleId = ""; // title_id: "mytitle" or ""(no title)

    var tailId = "tail_id"; // tail_id: "mytail" or ""(no tail)

    var titleType = 2; // 0 no title, 1 for first page, 2 for all pages, title: "" or "first" or "首页"
    var tailType = 2; // 0 no tail, 1 for first page, 2 for all pages, tail: "" or "first" or "首页"
    var color = 0; //0: remove colors, color: "" or "color" or "彩色"
    var button = 0; //0: hide buttons, button: "" or "button"
    var pageList = new Array(); //page list to print, page_list: [0,1-5]
    var pageRows = 17; // 0 don't break page, >0 data rows per page, page_rows: 10
    var secondRows = pageRows; //data rows of the pages except the first one, if different, second_rows: 15
    var blank = 0; //0 not blank table, other is blank pages, blank: 0 or 10
    var hiddenCols = new Array(); //hidden columns list, hidden_cols:[0,2,3-5]
    var paperHeight = 0; //use paper height to break page? paper_height:"720", must be larger than 300
    var paperWidth = 940;
    var blankLineHeight = 40; //line height in blank pages, blank_line_height:"40" or empty

    var contentRowClassName = "content-row";
    var pageBreaking = 0; //不分页


    var printDiv;
    //divs in new page
    var titleDiv;
    var tableDiv;
    var contentDiv;
    var tailDiv;
    var thead = "";
    var tbody = "";
    var tfoot = "";

    var eldialog = 0; //if this is an el-dialog, 1 is, 0 not
    var eltable = 0; //if this is an el-table,1 is, 0 not
    var firstRow = 0; //first data row number, 0 for all

    var headColIndexArray = new Array();

    var titleHeight = 0;
    var theadHeight = 0;
    var tfootHeight = 0;
    var tailHeight = 0;

    const titleDivClass = "titleDivClass";
    const tableDivClass = "tableDivClass";
    const contentDivClass = "contentDivClass";
    const tailDivClass = "tailDivClass";

    const theadClass = "theadClass"; //table header section's class
    const tbodyClass = "tbodyClass"; //table body section's class
    const tfootClass = "tfootClass"; //table foot section's class

    //print_id
    if (
        typeof printParam.print_id != "string" ||
        printParam.print_id.length < 2
    ) {
        alert("打印区(print_id)未指定!");
        return;
    }
    var printDiv = document.getElementById(printParam.print_id);
    if (!printDiv) {
        alert("获取打印区内容失败!");
        return;
    }

    handleInputs(printDiv);

    var trRows = printDiv.getElementsByClassName(contentRowClassName);  //all rows in print region
    if (!trRows) trRows = [];

    //get title and height, by title_id or el-dialog title
    titleDiv = document.createElement("div");
    //if this is an el-dialog?
    var wrapperClass = ""; //el-dialog wrapper class name
    var dialogClass = "";  //el-dialog-class name
    var header = printDiv.getElementsByClassName("el-dialog__header");
    if (header.length > 0) {
        eldialog = 1;
        titleDiv.innerHTML = header[0].outerHTML;
        titleHeight = header[0].clientHeight;
        //all el-dialog's class attrs
        var wrapper = printDiv.getElementsByClassName("el-dialog__wrapper");
        if (wrapper.length > 0) {
            var classNames = wrapper[0].getAttribute("class");
            if (classNames.length > 0) {
                var wrapperClass = classNames.replace("el-dialog__wrapper", "");
            }
        }
        var wrapper = printDiv.getElementsByClassName("el-dialog");
        if (wrapper.length > 0) {
            var classNames = wrapper[0].getAttribute("class");
            if (classNames.length > 0) {
                var dialogClass = classNames.replace("el-dialog", "");
            }
        }
    }
    else if (typeof printParam.title_id == "string" && printParam.title_id.length > 1) {
        var header = printDiv.getElementById(printParam.title_id);
        if (header) {
            titleDiv.innerHTML = header.outerHTML;
            titleHeight = header.clientHeight;
        }
    }

    //tail_id
    tailDiv = document.createElement("div");
    if (typeof printParam.tail_id == "string" && printParam.tail_id.length > 1) {
        var tail = document.getElementById(printParam.tail_id);
        if (tail) {
            tailDiv.innerHTML = tail.outerHTML;
            tailHeight = tail.clientHeight;
        }
    }

    //table_id
    if (
        typeof printParam.table_id == "undefined" ||
        printParam.table_id.length < 2
    ) {
        //("表(table_id)未指定!");
        printParam.table_id = "-";
    }
    tableId = printParam.table_id;
    var div = document.getElementById(tableId);
    if (div == null) {
        //alert("获取表格div失败!");
    }

    //paper height
    var value = parseInt(printParam.paper_height);
    if (value == value && value >= 300) {
        paperHeight = value;
        if (titleHeight + theadHeight + tfootHeight + tailHeight > paperHeight - 100) {
            alert("纸张长度设置太小，放不下表头表尾内容...");
            return;
        }
        else if( pageBreaking) alert("按纸张长度" + paperHeight + "自动分页...")
    }
    //paper width
    var value = parseInt(printParam.paper_width);
    if (value == value && value >= 300) {
        paperWidth = value;
    } else paperWidth = 300;

    //page_rows & second_rows
    var value = parseInt(printParam.page_rows);
    if (value != value && paperHeight < 300) {
        alert("纸张长度及每页行数均未指定,将不分页打印.");
        pageRows = 0;
    } else if (value == value) {
        pageRows = value;
        if (paperHeight < 300 && pageBreaking)
            alert("将按每页" + pageRows + "行自动分页...");
    }

    secondRows = pageRows;
    if (
        typeof printParam.second_rows != "undefined" &&
        parseInt(printParam.second_rows) > 0
    ) {
        secondRows = parseInt(printParam.second_rows);
    }
    if (pageRows == 0) secondRows = 0;
    //no page break
    else if (pageRows < 0) pageRows = secondRows = 17;
    if (secondRows < 0) secondRows = pageRows;

    //color
    if (
        typeof printParam.color != "undefined" &&
        (printParam.color == "color" || printParam.color == "彩色")
    ) {
        color = 1; //keep colors
    }

    //button
    if (
        typeof printParam.button != "undefined" &&
        (printParam.button == "button" || printParam.button == "打印")
    ) {
        button = 1; //keep buttons
    }

    //blank pages?
    if (
        typeof printParam.blank != "undefined" &&
        parseInt(printParam.blank) > 0
    ) {
        blank = parseInt(printParam.blank);
    }

    // title in first page only
    if (
        typeof printParam.title != "undefined" &&
        (printParam.title == "first" || printParam.taill == "首页")
    ) {
        titleType = 1; // title only for first page
    }

    //tail in first page only?
    if (
        typeof printParam.tail != "undefined" &&
        (printParam.tail == "first" || printParam.taill == "首页")
    ) {
        tailType = 1; // tail only for first page
    }

    var cssContent = "<style>";

    cssContent += handleDivStyle(titleDiv, printParam.title_font, printParam.title_font_size);
    cssContent += handleDivStyle(tailDiv, printParam.tail_font, printParam.tail_font_size);
    cssContent += handleTableStyle(thead, printParam.thead_font, printParam.thead_font_size,
        printParam.thead_line_height);
    cssContent += handleTableStyle(tbody, printParam.tbody_font, printParam.tbody_font_size,
        printParam.tbody_line_height);
    cssContent += handleTableStyle(tfoot, printParam.tfoot_font, printParam.tfoot_font_size,
        printParam.tfoot_line_height);

    cssContent += handleClassStyle(titleDivClass, printParam.title_style);
    cssContent += handleClassStyle(contentDivClass, printParam.tbody_style);
    cssContent += handleClassStyle(tailDivClass, printParam.tail_style);
    cssContent += handleClassStyle(theadClass, printParam.thead_style);
    cssContent += handleClassStyle(tbodyClass, printParam.tbody_style);
    cssContent += handleClassStyle(tfootClass, printParam.tfoot_style);
    //cssContent += "</style>";
    cssContent += "td{border:" + borderStyle + ";}th{border:" + borderStyle + ";font-weight:normal;}</style>";

    var rowCount = trRows.length - firstRow;
    if(!pageBreaking) rowCount=1;

    var pages = 1;

    if (pageRows == 0) pageRows = secondRows = rowCount;
    else if (rowCount < pageRows) pages = 0;
    else pages = 1 + parseInt((rowCount - pageRows) / secondRows);

    if (blank > 0) {
        pages = blank;
        rowCount = pageRows + (pages - 1) * secondRows;
        pageList.length = 0;
    }

    //blank page line height
    if (blank > 0) {
        if (isNaN(parseInt(printParam.blank_line_height)))
            blankLineHeight = blankLineHeight;
        else blankLineHeight = parseInt(printParam.blank_line_height);
        alert("将打印 " + blank + "页空表...");
    }

    var htmlContent = "";

    var rowIndex = firstRow;
    var outPages = 0;

    var pageHeight = 0;
    var height = 0;
    var newTableTrs = "";
    var pageFull = 0;
    var meetEnd = 0;

    //按指定的纸张高度自动分页
    if (paperHeight >= 300) {

        //cssContent = "";

        var newPage = 1;
        var pwin = window;//.open("_blank", "打印预览");

        var cssStyle = pwin.document.createElement("style");
        cssStyle.innerHTML = cssContent;
        pwin.document.getElementsByTagName("html")[0].appendChild(cssStyle);
        var htmlBody = pwin.document.getElementsByTagName("body")[0];

        var pagesDiv = pwin.document.createElement("div");
        pagesDiv.setAttribute("visibility", "hidden");
        pagesDiv.setAttribute("id", "pagesDiv");
        pagesDiv.style.width = paperWidth + "px";

        pagesDiv.style.paddingLeft = "10px";
        pagesDiv.style.paddingRight = "10px";

        htmlBody.appendChild(pagesDiv);

        if (blank > 0) {
            pages = blank;
            rowCount = pages * 100;
        }
        else pages = 10000;

        for (var i = 0; i < rowCount && outPages < pages; i++, rowIndex++) {

            if (outPages > 200) {
                alert("页数太多，中止...");
                break;
            }
            if (newPage) {

                //新一页
                //换行符
                var sep = pwin.document.createElement("div");
                if (outPages > 0) {
                    sep.style.pageBreakAfter = "always";
                }
                //换页
                pagesDiv.appendChild(sep);

                var pageDiv = pwin.document.createElement("div");
                pageDiv.style.paddingTop = "10px";
                pagesDiv.appendChild(pageDiv);

                if (eldialog) {
                    var attrs = printDiv.attributes;
                    for (var j = 0; j < attrs.length; j++) {
                        if (attrs[j].nodeName != "id")
                            pageDiv.setAttribute(attrs[j].nodeName, attrs[j].nodeValue);
                    }
                    pageDiv.setAttribute("class", wrapperClass + " " + dialogClass);
                }

                //抬头
                var ttlDiv = pwin.document.createElement("div");
                if (titleType == 0 || (titleType == 1 && outPages != 0)) {
                    //no title
                } else {
                    //title
                    ttlDiv.innerHTML = titleDiv.outerHTML;
                }
                ttlDiv.setAttribute("class", titleDivClass + " " + titleDiv.getAttribute("class"));
                pageDiv.appendChild(ttlDiv);

                //身体
                var bodyDiv = pwin.document.createElement("div");
                if (eldialog) {
                    bodyDiv.setAttribute("class", "el-dialog__body" + " " + tbodyClass);
                }
                else bodyDiv.setAttribute("class", tbodyClass);

                pageDiv.appendChild(bodyDiv);
            }

            //分页
            if (pageBreaking) {
                //添加一行数据
                var newTr = pwin.document.createElement("div");
                newTr.innerHTML = trRows[rowIndex].outerHTML;
                bodyDiv.appendChild(newTr);
            }//不分页
            else {
                if (eldialog) {
                    bodyDiv.innerHTML = printDiv.getElementsByClassName("el-dialog__body")[0].innerHTML;
                }
                else {
                    bodyDiv.innerHTML = printDiv.outerHTML;
                }
            }
            //签名栏
            var tlDiv = pwin.document.createElement("div");
            if (tailType == 0 || (tailType == 1 && outPages != 0)) {
                //no tail
            } else {
                //tail
                tlDiv.innerHTML = tailDiv.outerHTML;
                tlDiv.setAttribute("class", tailDivClass + " " + tailDiv.getAttribute("class"));
            }
            pageDiv.appendChild(tlDiv);

            if (pageBreaking) { }
            else break;

            height = pageDiv.clientHeight;

            //此行不能添加，直接分页
            if (height > paperHeight) {
                pageFull = 1;
                bodyDiv.removeChild(newTr); newTr.remove();
                //pageDiv.removeChild(tlDiv); tlDiv.remove();
            }
            else pageFull = 0;
            if (rowIndex + 1 == rowCount) meetEnd = 1;
            else meetEnd = 0;

            if (pageFull || (!pageFull && meetEnd)) {
                /*
                                htmlContent += pageDiv.outerHTML;
                                pagesDiv.removeChild(pageDiv);
                                pageDiv.removeChild(ttlDiv); ttlDiv.remove();
                                pageDiv.removeChild(tlDiv); tlDiv.remove();
                                pageDiv.removeChild(sep); sep.remove();
                                pageDiv.remove();
                */
                if (pageFull) {
                    i--; rowIndex--; newPage = 1;
                }
                outPages++;
            }
            else {
                pageDiv.removeChild(tlDiv); tlDiv.remove();
                newPage = 0;
            }
        }
        handleInputsColor(pagesDiv, color);
        handleButtons(pagesDiv, button, color);

        htmlContent = pagesDiv.outerHTML;

        pagesDiv.parentNode.removeChild(pagesDiv);
        pagesDiv.remove();
        if (cssStyle == "object") {
            cssStyle.parentNode.removeChild(cssStyle);
            cssStyle.remove();
        }
    }
    //按每页行数进行分页切割
    else {

    }
    //完成完整页面
    var printerStyle = getPrinterStyle(printParam);
    var printStr = "<html>" + document.getElementsByTagName("head")[0].outerHTML;
    printStr += "<body>" + htmlContent + "</body>";
    printStr += cssContent + printerStyle;

    if (!eldialog) {
        var styles = document.getElementsByTagName("style");
        if (styles != null) {
            for (var i = 0; i < styles.length; i++) {
                printStr += styles[i].outerHTML;
            }
        }
    }
    printStr += printerStyle + "</html>";
    htmlContent = "";

    if (1) {
        // 打开新页面
        var pwin = window.open("_blank", "打印预览");

        if (pwin == null) {
            alert("行数较多, 请点确定返回后再尝试打印一次!");
            return;
        }
        // 将内容赋值到新页面

        pwin.document.write(printStr);

        var winTitle=pwin.document.getElementsByTagName("head")[0].getElementsByTagName("title");
        if( winTitle && winTitle.length>0){
            winTitle[0].innerHTML='`';
        }
        pwin.document.close();
        if (!(typeof printParam.preview != "undefined" && printParam.preview == "预览")) {

            // 聚焦-不加focuse，在某些情况下，打印页面会有问题。
            pwin.focus();
            // 使用setTimeout，等页面dom元素渲染完成后再打印。

            setTimeout(function () {
                pwin.print(); // 打印功能。 例如 window.print() 直接打印当前整个页面。
                pwin.close(); // 关闭 打印创建的当前页面
                //window.location.reload();
            }, 800);
        }
    }
}

function createAllSections(printParam, sectionGroup, eltable) {
    var heightObj = new Object();
    heightObj.height = 0;

    sectionGroup.tableDiv = createSection(printParam.table_id, heightObj);
    sectionGroup.ContentDiv = createSection(printParam.print_id, heightObj);

    sectionGroup.titleDiv = createSection(printParam.title_id, heightObj);
    sectionGroup.titleHeight = heightObj.height;

    sectionGroup.tailDiv = createSection(printParam.tail_id, heightObj);
    sectionGroup.tailHeight = heightObj.height;

    if (eltable) {

        var thead = document.createElement("thead");
        thead.innerHTML = document.getElementById(printParam.table_id).getElementsByTagName("thead")[0].innerHTML;
        var theadHeight = document.getElementById(printParam.table_id).getElementsByTagName("thead")[0].clientHeight;

        var tbody = document.createElement("tbody");
        tbody.innerHTML = document.getElementById(printParam.table_id).getElementsByTagName("tbody")[0].innerHTML;
        var trRows = tbody.getElementsByTagName("tr");

        var tfoot = createSection("", heightObj);
        var tfootHeight = 0;
    }
    else {
        var thead = createSection(printParam.table_head, heightObj);
        var theadHeight = heightObj.height;
        var tbody = createSection(printParam.table_body, heightObj);
        var trRows = tbody.getElementsByTagName("tr");

        var tfoot = createSection(printParam.table_foot, heightObj);
        var tfootHeight = heightObj.height;
    }

    sectionGroup.thead = thead;
    sectionGroup.theadHeight = theadHeight;

    sectionGroup.tbody = tbody;
    sectionGroup.trRows = trRows;

    sectionGroup.tfoot = tfoot;
    sectionGroup.tfootHeight = tfootHeight;

}
//copy a div and return the new one
function createSection(sectionId, heightObj) {
    heightObj.height = 0;

    if (
        typeof sectionId != "string" ||
        sectionId.length < 2
    ) {
        return document.createElement("div");
    }

    var div = document.getElementById(sectionId);
    if (div == null) return document.createElement("div");
    var headTag = div.tagName;
    if (headTag == null) {
        return document.createElement("div");
    }
    else {
        var section = document.createElement(headTag);
        section.innerHTML = div.innerHTML;
        section.setAttribute("id", sectionId);
        section.setAttribute("class", div.getAttribute("class"));
        section.setAttribute("style", div.getAttribute("style"));
        heightObj.height = div.clientHeight;

        return section;
    }

}
//hide buttons and set their color
function handleButtons(thisDiv, button, color) {
    if (typeof thisDiv != "object") return;
    var buttons = thisDiv.getElementsByTagName("button");
    for (var i = 0; i < buttons.length; i++) {
        if (!button) buttons[i].style.visibility = "hidden";
        if (!color) {
            buttons[i].style.color = "black";
            buttons[i].style.background = "white";
        }
    }
}
//write content to all inputs
function handleInputs(thisDiv) {
    if (typeof thisDiv != "object") return;
    var inputs = thisDiv.getElementsByTagName("input");

    for (var k = 0; k < inputs.length; k++) {
        if (inputs[k].type == "checkbox" || inputs[k].type == "radio") {
            if (inputs[k].checked == true) {
                inputs[k].setAttribute("checked", "checked");
            } else {
                inputs[k].removeAttribute("checked");
            }
        } else if (inputs[k].type == "text") {
            inputs[k].setAttribute("value", inputs[k].value);
        } else {
            inputs[k].setAttribute("value", inputs[k].value);
        }
    }

    var textareas = thisDiv.querySelectorAll('textarea');
    for (var k = 0; k < textareas.length; k++) {
        if (textareas[k].type == 'textarea') {
            textareas[k].innerHTML = textareas[k].value;
        }
    }
    var selects = thisDiv.querySelectorAll('select');
    for (var k = 0; k < selects.length; k3++) {
        if (selects[k].type == 'select-one') {
            var child = selects[k].children;
            for (var i in child) {
                if (child[i].tagName == 'OPTION' || child[i].tagName == 'option') {
                    if (child[i].selected == true)
                        child[i].setAttribute('selected', "selected");
                    else
                        child[i].removeAttribute('selected');
                }

            }
        }
    }
    //添加打印插件  hxl 添加 体温单打印出现不了绘制的图像
  //canvass echars图表转为图片
  /**
  var canvass = document.querySelectorAll('canvas');
  var isNeedRemove = document.querySelectorAll('.isNeedRemove')
  for (var k4 = 0; k4 < canvass.length; k4++) {
    if (isNeedRemove.length == 0) {
      var imageURL = canvass[k4].toDataURL("image/png");
      var img = document.createElement("img");
      img.src = imageURL;
      img.setAttribute('style', 'max-width: 100%;');
      img.className = 'isNeedRemove'+k4;
      canvass[k4].style.display = 'none'
      //canvass[k4].parentNode.style.width = '100%'
      //canvass[k4].parentNode.style.textAlign = 'center'
      canvass[k4].parentNode.insertBefore(img, canvass[k4].nextElementSibling);
    }
  }
   **/

}
//set inputs' color
function handleInputsColor(thisDiv, color) {
    if (color) return;
    if (typeof thisDiv != "object") return;
    var inputs = thisDiv.getElementsByTagName("input");

    for (var k = 0; k < inputs.length; k++) {
        inputs[k].style.color = "black";
    }

    var textareas = thisDiv.querySelectorAll('textarea');
    for (var k = 0; k < textareas.length; k++) {
        textareas[k].style.color = "black";
    }
}
function handleClassStyle(className, styleString) {

    if (typeof className != "string" || typeof styleString != "string") return "";
    if (className.length < 4 || styleString.length < 4) return "";
    var css = " ." + className + "{ " + styleString + "} ";
    return css;
}
//set font-size and return css content
function handleDivStyle(thisDiv, fontFamily, fontSize) {
    if (typeof thisDiv != "object") return "";
    var className = thisDiv.getAttribute("class");
    if (typeof fontSize != "undefined" && parseInt(fontSize) > 1) {
        var size = parseInt(fontSize) + "px";

        thisDiv.style.fontSize = size;
        var items = thisDiv.getElementsByTagName("span");
        for (var i = 0; i < items.length; i++) {
            //items[i].style.fontSize = size;
            var className = items[i].getAttribute("class");
            if (className == null) className = thisDiv.getAttribute("class");
            else className += "   " + thisDiv.getAttribute("class");
            items[i].setAttribute("class", className);
        }
    }
    if (typeof fontFamily == "string" && fontFamily.length > 1) {

        if (className != null) {
            var css = " ." + className + "{font-family:" + "'" + fontFamily + "'} ";
            return css;
        }
    }
    return "";
}
//set font-size and return css content
function handleTableStyle(thisTable, fontFamily, fontSize, lineHeight) {

    if (typeof thisTable != "object") return "";
    var className = thisTable.getAttribute("class");
    var items = thisTable.getElementsByTagName("tr");

    if (className != null) {
        for (var i = 0; i < items.length; i++) {
            var trClass = items[i].getAttribute("class");

            if (trClass != null) trClass += "  " + className;
            else trClass = className;
            items[i].setAttribute("class", trClass);
        }
    }
    if (typeof lineHeight != "undefined" && parseInt(lineHeight) > 1) {


        var size = parseInt(lineHeight) + "px";
        if (thisTable.getAttribute("style") == null)
            thisTable.setAttribute("style", "line-height:" + size);
        else thisTable.style.lineHeight = size;


        var items = thisTable.getElementsByTagName("tr");
        for (var i = 0; i < items.length; i++) {
            items[i].style.height = size;
        }
    }
    if (typeof fontSize != "undefined" && parseInt(fontSize) > 1) {

        var size = parseInt(fontSize) + "px";
        thisTable.style.fontSize = size;

        var items = thisTable.getElementsByTagName("th");
        for (var i = 0; i < items.length; i++) {
            items[i].style.fontSize = size;
        }
        items = thisTable.getElementsByTagName("td");
        for (var i = 0; i < items.length; i++) {
            items[i].style.fontSize = size;
        }
    }
    if (typeof fontFamily == "string" && fontFamily.length > 1) {

        if (className != null) {
            var css = " ." + className + "{font-family:" + "'" + fontFamily + "'} ";
            return css;
        }
    }
    return "";
}
function getPrinterStyle(printParam) {

    if (typeof printParam == "undefined") return "";

    var printerStyle = "<style>@media print{ th{";

    if ((typeof printParam.th_font_size == "string" || typeof printParam.th_font_size == "number")
        && parseInt(printParam.th_font_size) > 2) {
        printerStyle += "font-size:" + parseInt(printParam.th_font_size) + "px;";
    }
    if ((typeof printParam.th_line_height == "string" || typeof printParam.th_line_height == "number")
        && parseInt(printParam.th_line_height) > 2) {
        printerStyle += "line-height:" + parseInt(printParam.th_line_height) + "px;";
    }
    if (typeof printParam.th_font != "undefined" && typeof printParam.th_font == "string"
        && printParam.th_font.length > 1) {
        printerStyle += "font-family:'" + printParam.th_font + "'";
    }
    printerStyle += "}  td{";

    if ((typeof printParam.td_font_size == "string" || typeof printParam.td_font_size == "number")
        && parseInt(printParam.td_font_size) > 2) {
        printerStyle += "font-size:" + parseInt(printParam.td_font_size) + "px;";
    }
    if ((typeof printParam.td_line_height == "string" || typeof printParam.td_line_height == "number")
        && parseInt(printParam.td_line_height) > 2) {
        printerStyle += "line-height:" + parseInt(printParam.td_line_height) + "px;";
    }

    if (typeof printParam.td_font != "undefined" && typeof printParam.td_font == "string"
        && printParam.td_font.length > 1) {
        printerStyle += "font-family:'" + printParam.td_font + "'";
    }
    printerStyle += "} </style>";

    printerStyle = ""; //font-family因为引号无法正确设置，放弃不用
    printerStyle = "<style>\
        @media print {\
            body{\
            -webkit-print-color-adjust:exact;\
            -moz-print-color-adjust:exact;\
            -ms-print-color-adjust:exact;\
            print-color-adjust:exact;\
            } \
            button{display:none;}\
        }\
        </style>";
    return printerStyle;
}
